package com.hj.demo.homework;

public class Test3 {
    public static void main(String[] args) {
        Student student = new Student("王小明", 20, "1001", "男");
        Student student1 = new Student("刘小红", 20, "1002", "女");
        student.study();
        student.sleep();
        student.eat();
        if (student.name.equals(student1.name)&&student.id.equals(student1.id)){
            System.out.println("相同");
        }else {
            System.out.println("不相同");
        }
    }
}
class Student{
    public String name;
    public int age;
    public String id;
    public String sex;

    public Student(String name, int age, String id, String sex) {
        this.name = name;
        this.age = age;
        this.id = id;
        this.sex = sex;
    }

    public void study(){
        System.out.println("学习");
    }
    public void sleep(){
        System.out.println("睡觉");
    }
    public void eat(){
        System.out.println("吃饭");
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Student student = (Student) o;

        if (name != null ? !name.equals(student.name) : student.name != null) return false;
        return id != null ? id.equals(student.id) : student.id == null;
    }

    @Override
    public int hashCode() {
        int result = name != null ? name.hashCode() : 0;
        result = 31 * result + (id != null ? id.hashCode() : 0);
        return result;
    }
}
